package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IAccidentService;
import cn.wolfcode.crm.service.IClaimBillService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("compensationBill")
public class CompensationBillController {
    @Autowired
    private IAccidentService service;
    @Autowired
    private IClaimBillService claimBillService;
    @RequiresPermissions("compensationBill:index")
    @PermissionName("事故理赔单首页")
    @RequestMapping("")
    private String index(){
        return "compensationBill/list";
    }
    /*
     * 查询审核完成,待支付的数据
     * */
    @RequestMapping("listByCompensation")
    @ResponseBody
    private PageResult listByCompensation(QueryObject qo){
        return  service.listByCompensation(qo);
    }
    /*
     * 更改数据状态为已支付
     * */
    @RequestMapping("updateStateToPaied")
    @ResponseBody
    private JsonResult updateStateToPaied(Long id,String insuranceNo){
        JsonResult result = new JsonResult();
        try {
            service.updateStateToPaied(id);
            claimBillService.changePaiedState(insuranceNo);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("提交验证失败");
        }
        return result;
    }
}
